package com.imooc.course.business.controller.album;

import com.imooc.course.business.form.ShortMessagingServiceForm;
import com.imooc.course.server.dto.ResponseDto;
import com.imooc.course.server.dto.ShortMessagingServiceDto;
import com.imooc.course.server.entity.ShortMessagingService;
import com.imooc.course.server.enums.SmsUseEnum;
import com.imooc.course.server.service.ShortMessagingServiceService;
import com.imooc.course.server.utils.CopyUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/album/sms")
public class AlbumSmsController {

    private static final Logger log = LoggerFactory.getLogger(AlbumSmsController.class);
    public static final String BUSINESS_NAME = "短信验证码";

    @Resource(name = "shortMessagingServiceService")
    private ShortMessagingServiceService shortMessagingServiceService;

    /**
     * 发送短信验证码
     * 同手机号同操作1分钟内不能重复发送短信
     * @param smsForm
     * @return
     */
    @PostMapping("/send")
    public ResponseDto send(@RequestBody ShortMessagingServiceForm smsForm) {
        log.info("发送短信请求开始: {}", smsForm);
        shortMessagingServiceService.sendCode(CopyUtil.copy(smsForm, ShortMessagingServiceDto.class));
        log.info("发送短信请求结束");
        return ResponseDto.success();
    }


}
